﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Experimental8.Common.Data.EDM;
using Experimental8.Infrastructure;
using Experimental8.Infrastructure.DAL.Interfaces;
using Microsoft.Practices.Prism.Mvvm;

namespace Experimental8.Modules.CommonDictionaries
{
    [Export(typeof(ContractorsViewModel))]
    [PartCreationPolicy(System.ComponentModel.Composition.CreationPolicy.NonShared)]
    public class ContractorsViewModel : BindableBase, IContractorsViewModel
    {
        private IDACommonDictionariesService _daCommonDictionariesService;
        private IDAInfrastructureService _daInfrastructureService;

        private ObservableCollection<contractor> _contractors;
        public ObservableCollection<contractor> Contractors
        {
            get { return this._contractors; }
            set 
            {
                if (this._contractors != value)                                 
                    this.SetProperty(ref this._contractors, value);                               
            }
        }

        ObservableCollection<ui_fields_information_item> _contractor_Fields_Information;
        public ObservableCollection<ui_fields_information_item> Contractor_Fields_Information
        {
            get { return this._contractor_Fields_Information; }
            set
            {
                if (this._contractor_Fields_Information != value)
                    this.SetProperty(ref this._contractor_Fields_Information, value);
            }
        }

        [ImportingConstructor]
        public ContractorsViewModel(IDACommonDictionariesService daCommonDictionariesService, IDAInfrastructureService daInfrastructureService)
        {
            this._daCommonDictionariesService = daCommonDictionariesService;
            this._daInfrastructureService = daInfrastructureService;
            this.LoadData();
        }

        private void LoadData()
        {
            this.Contractor_Fields_Information = this._daInfrastructureService.GetUIfieldsInformationItemByCode(UiLinkNames.contractor);            
            this.Contractors = this._daCommonDictionariesService.GetContractors();
        }

        public string HeaderInfo
        { 
            get { return "Контрагенты"; } 
        }
    }
}
